/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model.pojo;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Yasith
 */
@Entity
@Table(name = "votes")
@NamedQueries({@NamedQuery(name = "Vote.findByVoteId", query = "SELECT v FROM Vote v WHERE v.voteId = :voteId"), @NamedQuery(name = "Vote.findByVoteText", query = "SELECT v FROM Vote v WHERE v.voteText = :voteText"), @NamedQuery(name = "Vote.findByTimestamp", query = "SELECT v FROM Vote v WHERE v.timestamp = :timestamp"), @NamedQuery(name = "Vote.findByExpireDate", query = "SELECT v FROM Vote v WHERE v.expireDate = :expireDate")})
public class Vote implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue
    @Column(name = "voteId", nullable = false)
    private Integer voteId;
    @Column(name = "voteText")
    private String voteText;
    @Column(name = "timestamp")
    @Temporal(TemporalType.TIMESTAMP)
    private Date timestamp;
    @Column(name = "expireDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date expireDate;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "voteId")
    private Collection<VoteResult> voteresultsCollection;

    public Vote() {
    }

    public Vote(Integer voteId) {
        this.voteId = voteId;
    }

    public Integer getVoteId() {
        return voteId;
    }

    public void setVoteId(Integer voteId) {
        this.voteId = voteId;
    }

    public String getVoteText() {
        return voteText;
    }

    public void setVoteText(String voteText) {
        this.voteText = voteText;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    public Date getExpireDate() {
        return expireDate;
    }

    public void setExpireDate(Date expireDate) {
        this.expireDate = expireDate;
    }

    public Collection<VoteResult> getVoteresultsCollection() {
        return voteresultsCollection;
    }

    public void setVoteresultsCollection(Collection<VoteResult> voteresultsCollection) {
        this.voteresultsCollection = voteresultsCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (voteId != null ? voteId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Vote)) {
            return false;
        }
        Vote other = (Vote) object;
        if ((this.voteId == null && other.voteId != null) || (this.voteId != null && !this.voteId.equals(other.voteId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.pojo.Vote[voteId=" + voteId + "]";
    }

}
